package leetcode.code036;

public class Solution1 extends Solution036 {

	@Override
	public boolean isValidSudoku(char[][] board) {
		final int len = 9;
		boolean[][] check = new boolean[len * 3][len + 1];
		for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				char c = board[i][j];
				if (c == '.')
					continue;
				int ic = c - '0';
				int x1 = i;
				if (!check[x1][ic])
					check[x1][ic] = true;
				else
					return false;
				int x2 = j + len;
				if (!check[x2][ic])
					check[x2][ic] = true;
				else
					return false;
				int x3 = -1;
				if (i >= 0 && i <= 2 && j >= 0 && j <= 2) {
					x3 = 18;
				} else if (i >= 0 && i <= 2 && j >= 3 && j <= 5) {
					x3 = 19;
				} else if (i >= 0 && i <= 2 && j >= 6 && j <= 8) {
					x3 = 20;
				} else if (i >= 3 && i <= 5 && j >= 0 && j <= 2) {
					x3 = 21;
				} else if (i >= 3 && i <= 5 && j >= 3 && j <= 5) {
					x3 = 22;
				} else if (i >= 3 && i <= 5 && j >= 6 && j <= 8) {
					x3 = 23;
				} else if (i >= 6 && i <= 8 && j >= 0 && j <= 2) {
					x3 = 24;
				} else if (i >= 6 && i <= 8 && j >= 3 && j <= 5) {
					x3 = 25;
				} else if (i >= 6 && i <= 8 && j >= 6 && j <= 8) {
					x3 = 26;
				}
				if (!check[x3][ic])
					check[x3][ic] = true;
				else
					return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();

	}

}
